/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#include "pch.h"
#include <Windows.h>
#include <esent.h>
#include <string>
#include <baja/db/engines/jet/db_jet_error.h>

using namespace baja::storage;

std::string GetJETErrorString(long error, std::string contextString)
{
    std::string errorString = "ERROR: JET DB ENGINE: \n    ";
    errorString += contextString;
    errorString += "\n\t";
    switch (error)
    {
        case JET_errSuccess: errorString += "JET_errSuccess"; break;
        // SYSTEM errors
        case JET_errRfsFailure: errorString += "JET_errRfsFailure"; break;
        case JET_errRfsNotArmed: errorString += "JET_errRfsNotArmed"; break;
        case JET_errFileClose: errorString += "JET_errFileClose"; break;
        case JET_errOutOfThreads: errorString += "JET_errOutOfThreads"; break;
        case JET_errTooManyIO: errorString += "JET_errTooManyIO"; break;
        case JET_errTaskDropped: errorString += "JET_errTaskDropped"; break;
        case JET_errInternalError: errorString += "JET_errInternalError"; break;

        //BUFFER MANAGER errors
        //
        case JET_errDatabaseBufferDependenciesCorrupted: errorString += "JET_errDatabaseBufferDependenciesCorrupted"; break;

        // DIRECTORY MANAGER errors
        //
        case JET_errPreviousVersion: errorString += "JET_errPreviousVersion"; break;
        case JET_errPageBoundary: errorString += "JET_errPageBoundary"; break;
        case JET_errKeyBoundary: errorString += "JET_errKeyBoundary"; break;
        case JET_errBadPageLink: errorString += "JET_errBadPageLink"; break;
        case JET_errBadBookmark: errorString += "JET_errBadBookmark"; break;
        case JET_errNTSystemCallFailed: errorString += "JET_errNTSystemCallFailed"; break;
        case JET_errBadParentPageLink: errorString += "JET_errBadParentPageLink"; break;
        case JET_errSPAvailExtCacheOutOfSync: errorString += "JET_errSPAvailExtCacheOutOfSync"; break;
        case JET_errSPAvailExtCorrupted: errorString += "JET_errSPAvailExtCorrupted"; break;
        case JET_errSPAvailExtCacheOutOfMemory: errorString += "JET_errSPAvailExtCacheOutOfMemory"; break;
        case JET_errSPOwnExtCorrupted: errorString += "JET_errSPOwnExtCorrupted"; break;
        case JET_errDbTimeCorrupted: errorString += "JET_errDbTimeCorrupted"; break;
        case JET_errKeyTruncated: errorString += "JET_errKeyTruncated"; break;
        case JET_errDatabaseLeakInSpace: errorString += "JET_errDatabaseLeakInSpace"; break;

        // RECORD MANAGER errors

        case JET_errKeyTooBig: errorString += "JET_errKeyTooBig"; break;
        case JET_errSeparatedLongValue: errorString += "JET_errSeparatedLongValue"; break;
        case JET_errMustBeSeparateLongValue: errorString += "JET_errMustBeSeparateLongValue"; break;
        case JET_errInvalidPreread: errorString += "JET_errInvalidPreread"; break;

        // LOGGING/RECOVERY errors

        case JET_errInvalidLoggedOperation: errorString += "JET_errInvalidLoggedOperation"; break;
        case JET_errLogFileCorrupt: errorString += "JET_errLogFileCorrupt"; break;
        case JET_errNoBackupDirectory: errorString += "JET_errNoBackupDirectory"; break;
        case JET_errBackupDirectoryNotEmpty: errorString += "JET_errBackupDirectoryNotEmpty"; break;
        case JET_errBackupInProgress: errorString += "JET_errBackupInProgress"; break;
        case JET_errRestoreInProgress: errorString += "JET_errRestoreInProgress"; break;
        case JET_errMissingPreviousLogFile: errorString += "JET_errMissingPreviousLogFile"; break;
        case JET_errLogWriteFail: errorString += "JET_errLogWriteFail"; break;
        case JET_errLogDisabledDueToRecoveryFailure: errorString += "JET_errLogDisabledDueToRecoveryFailure"; break;
        case JET_errCannotLogDuringRecoveryRedo: errorString += "JET_errCannotLogDuringRecoveryRedo"; break;
        case JET_errLogGenerationMismatch: errorString += "JET_errLogGenerationMismatch"; break;
        case JET_errBadLogVersion: errorString += "JET_errBadLogVersion"; break;
        case JET_errInvalidLogSequence: errorString += "JET_errInvalidLogSequence"; break;
        case JET_errLoggingDisabled: errorString += "JET_errLoggingDisabled"; break;
        case JET_errLogBufferTooSmall: errorString += "JET_errLogBufferTooSmall"; break;
        case JET_errLogSequenceEnd: errorString += "JET_errLogSequenceEnd"; break;
        case JET_errNoBackup: errorString += "JET_errNoBackup"; break;
        case JET_errInvalidBackupSequence: errorString += "JET_errInvalidBackupSequence"; break;
        case JET_errBackupNotAllowedYet: errorString += "JET_errBackupNotAllowedYet"; break;
        case JET_errDeleteBackupFileFail: errorString += "JET_errDeleteBackupFileFail"; break;
        case JET_errMakeBackupDirectoryFail: errorString += "JET_errMakeBackupDirectoryFail"; break;
        case JET_errInvalidBackup: errorString += "JET_errInvalidBackup"; break;
        case JET_errRecoveredWithErrors: errorString += "JET_errRecoveredWithErrors"; break;
        case JET_errMissingLogFile: errorString += "JET_errMissingLogFile"; break;
        case JET_errLogDiskFull: errorString += "JET_errLogDiskFull"; break;
        case JET_errBadLogSignature: errorString += "JET_errBadLogSignature"; break;
        case JET_errBadDbSignature: errorString += "JET_errBadDbSignature"; break;
        case JET_errBadCheckpointSignature: errorString += "JET_errBadCheckpointSignature"; break;
        case JET_errCheckpointCorrupt: errorString += "JET_errCheckpointCorrupt"; break;
        case JET_errMissingPatchPage: errorString += "JET_errMissingPatchPage"; break;
        case JET_errBadPatchPage: errorString += "JET_errBadPatchPage"; break;
        case JET_errRedoAbruptEnded: errorString += "JET_errRedoAbruptEnded"; break;
        case JET_errBadSLVSignature: errorString += "JET_errBadSLVSignature"; break;
        case JET_errPatchFileMissing: errorString += "JET_errPatchFileMissing"; break;
        case JET_errDatabaseLogSetMismatch: errorString += "JET_errDatabaseLogSetMismatch"; break;
        case JET_errDatabaseStreamingFileMismatch: errorString += "JET_errDatabaseStreamingFileMismatch"; break;
        case JET_errLogFileSizeMismatch: errorString += "JET_errLogFileSizeMismatch"; break;
        case JET_errCheckpointFileNotFound: errorString += "JET_errCheckpointFileNotFound"; break;
        case JET_errRequiredLogFilesMissing: errorString += "JET_errRequiredLogFilesMissing"; break;
        case JET_errSoftRecoveryOnBackupDatabase: errorString += "JET_errSoftRecoveryOnBackupDatabase"; break;
        case JET_errLogFileSizeMismatchDatabasesConsistent: errorString += "JET_errLogFileSizeMismatchDatabasesConsistent"; break;
        case JET_errLogSectorSizeMismatch: errorString += "JET_errLogSectorSizeMismatch"; break;
        case JET_errLogSectorSizeMismatchDatabasesConsistent: errorString += "JET_errLogSectorSizeMismatchDatabasesConsistent"; break;
        case JET_errLogSequenceEndDatabasesConsistent: errorString += "JET_errLogSequenceEndDatabasesConsistent"; break;
        case JET_errStreamingDataNotLogged: errorString += "JET_errStreamingDataNotLogged"; break;
        case JET_errDatabaseDirtyShutdown:  // same as JET_errDatabaseInconsistent
            errorString += "JET_errDatabaseDirtyShutdown OR JET_errDatabaseInconsistent\n"; 
            break;
        case JET_errConsistentTimeMismatch: errorString += "JET_errConsistentTimeMismatch"; break;
        case JET_errDatabasePatchFileMismatch: errorString += "JET_errDatabasePatchFileMismatch"; break;
        case JET_errEndingRestoreLogTooLow: errorString += "JET_errEndingRestoreLogTooLow"; break;
        case JET_errStartingRestoreLogTooHigh: errorString += "JET_errStartingRestoreLogTooHigh"; break;
        case JET_errGivenLogFileHasBadSignature: errorString += "JET_errGivenLogFileHasBadSignature"; break;
        case JET_errGivenLogFileIsNotContiguous: errorString += "JET_errGivenLogFileIsNotContiguous"; break;
        case JET_errMissingRestoreLogFiles: errorString += "JET_errMissingRestoreLogFiles"; break;
        case JET_errMissingFullBackup: errorString += "JET_errMissingFullBackup"; break;
        case JET_errBadBackupDatabaseSize: errorString += "JET_errBadBackupDatabaseSize"; break;
        case JET_errDatabaseAlreadyUpgraded: errorString += "JET_errDatabaseAlreadyUpgraded"; break;
        case JET_errDatabaseIncompleteUpgrade: errorString += "JET_errDatabaseIncompleteUpgrade"; break;
        case JET_errMissingCurrentLogFiles: errorString += "JET_errMissingCurrentLogFiles"; break;
        case JET_errDbTimeTooOld: errorString += "JET_errDbTimeTooOld"; break;
        case JET_errDbTimeTooNew: errorString += "JET_errDbTimeTooNew"; break;
        case JET_errMissingFileToBackup: errorString += "JET_errMissingFileToBackup"; break;
        case JET_errLogTornWriteDuringHardRestore: errorString += "JET_errLogTornWriteDuringHardRestore"; break;
        case JET_errLogTornWriteDuringHardRecovery: errorString += "JET_errLogTornWriteDuringHardRecovery"; break;
        case JET_errLogCorruptDuringHardRestore: errorString += "JET_errLogCorruptDuringHardRestore"; break;
        case JET_errLogCorruptDuringHardRecovery: errorString += "JET_errLogCorruptDuringHardRecovery"; break;
        case JET_errMustDisableLoggingForDbUpgrade: errorString += "JET_errMustDisableLoggingForDbUpgrade"; break;
        case JET_errBadRestoreTargetInstance: errorString += "JET_errBadRestoreTargetInstance"; break;
        case JET_errRecoveredWithoutUndo: errorString += "JET_errRecoveredWithoutUndo"; break;
        case JET_errDatabasesNotFromSameSnapshot: errorString += "JET_errDatabasesNotFromSameSnapshot"; break;
        case JET_errSoftRecoveryOnSnapshot: errorString += "JET_errSoftRecoveryOnSnapshot"; break;
        case JET_errCommittedLogFilesMissing: errorString += "JET_errCommittedLogFilesMissing"; break;
        case JET_errSectorSizeNotSupported: errorString += "JET_errSectorSizeNotSupported"; break;
        case JET_errRecoveredWithoutUndoDatabasesConsistent: errorString += "JET_errRecoveredWithoutUndoDatabasesConsistent"; break;
        case JET_errCommittedLogFileCorrupt: errorString += "JET_errCommittedLogFileCorrupt"; break;
        case JET_errUnicodeTranslationBufferTooSmall: errorString += "JET_errUnicodeTranslationBufferTooSmall"; break;
        case JET_errUnicodeTranslationFail: errorString += "JET_errUnicodeTranslationFail"; break;
        case JET_errUnicodeNormalizationNotSupported: errorString += "JET_errUnicodeNormalizationNotSupported"; break;
        case JET_errUnicodeLanguageValidationFailure: errorString += "JET_errUnicodeLanguageValidationFailure"; break;
        case JET_errExistingLogFileHasBadSignature: errorString += "JET_errExistingLogFileHasBadSignature"; break;
        case JET_errExistingLogFileIsNotContiguous: errorString += "JET_errExistingLogFileIsNotContiguous"; break;
        case JET_errLogReadVerifyFailure: errorString += "JET_errLogReadVerifyFailure"; break;
        case JET_errSLVReadVerifyFailure: errorString += "JET_errSLVReadVerifyFailure"; break;
        case JET_errCheckpointDepthTooDeep: errorString += "JET_errCheckpointDepthTooDeep"; break;
        case JET_errRestoreOfNonBackupDatabase: errorString += "JET_errRestoreOfNonBackupDatabase"; break;
        case JET_errLogFileNotCopied: errorString += "JET_errLogFileNotCopied"; break;
        case JET_errInvalidGrbit: errorString += "JET_errInvalidGrbit"; break;
        case JET_errTermInProgress: errorString += "JET_errTermInProgress"; break;
        case JET_errFeatureNotAvailable: errorString += "JET_errFeatureNotAvailable"; break;
        case JET_errInvalidName: errorString += "JET_errInvalidName"; break;
        case JET_errInvalidParameter: errorString += "JET_errInvalidParameter"; break;
        case JET_errDatabaseFileReadOnly: errorString += "JET_errDatabaseFileReadOnly"; break;
        case JET_errInvalidDatabaseId: errorString += "JET_errInvalidDatabaseId"; break;
        case JET_errOutOfMemory: errorString += "JET_errOutOfMemory"; break;
        case JET_errOutOfDatabaseSpace: errorString += "JET_errOutOfDatabaseSpace"; break;
        case JET_errOutOfCursors: errorString += "JET_errOutOfCursors"; break;
        case JET_errOutOfBuffers: errorString += "JET_errOutOfBuffers"; break;
        case JET_errTooManyIndexes: errorString += "JET_errTooManyIndexes"; break;
        case JET_errTooManyKeys: errorString += "JET_errTooManyKeys"; break;
        case JET_errRecordDeleted: errorString += "JET_errRecordDeleted"; break;
        case JET_errReadVerifyFailure: errorString += "JET_errReadVerifyFailure"; break;
        case JET_errPageNotInitialized: errorString += "JET_errPageNotInitialized"; break;
        case JET_errOutOfFileHandles: errorString += "JET_errOutOfFileHandles"; break;
        case JET_errDiskReadVerificationFailure: errorString += "JET_errDiskReadVerificationFailure"; break;
        case JET_errDiskIO: errorString += "JET_errDiskIO"; break;
        case JET_errInvalidPath: errorString += "JET_errInvalidPath"; break;
        case JET_errInvalidSystemPath: errorString += "JET_errInvalidSystemPath"; break;
        case JET_errInvalidLogDirectory: errorString += "JET_errInvalidLogDirectory"; break;
        case JET_errRecordTooBig: errorString += "JET_errRecordTooBig"; break;
        case JET_errTooManyOpenDatabases: errorString += "JET_errTooManyOpenDatabases"; break;
        case JET_errInvalidDatabase: errorString += "JET_errInvalidDatabase"; break;
        case JET_errNotInitialized: errorString += "JET_errNotInitialized"; break;
        case JET_errAlreadyInitialized: errorString += "JET_errAlreadyInitialized"; break;
        case JET_errInitInProgress: errorString += "JET_errInitInProgress"; break;
        case JET_errFileAccessDenied: errorString += "JET_errFileAccessDenied"; break;
        case JET_errBufferTooSmall: errorString += "JET_errBufferTooSmall"; break;
        case JET_errTooManyColumns: errorString += "JET_errTooManyColumns"; break;
        case JET_errContainerNotEmpty: errorString += "JET_errContainerNotEmpty"; break;
        case JET_errInvalidFilename: errorString += "JET_errInvalidFilename"; break;
        case JET_errInvalidBookmark: errorString += "JET_errInvalidBookmark"; break;
        case JET_errColumnInUse: errorString += "JET_errColumnInUse"; break;
        case JET_errInvalidBufferSize: errorString += "JET_errInvalidBufferSize"; break;
        case JET_errColumnNotUpdatable: errorString += "JET_errColumnNotUpdatable"; break;
        case JET_errIndexInUse: errorString += "JET_errIndexInUse"; break;
        case JET_errLinkNotSupported: errorString += "JET_errLinkNotSupported"; break;
        case JET_errNullKeyDisallowed: errorString += "JET_errNullKeyDisallowed"; break;
        case JET_errNotInTransaction: errorString += "JET_errNotInTransaction"; break;
        case JET_errMustRollback: errorString += "JET_errMustRollback"; break;
        case JET_errTooManyActiveUsers: errorString += "JET_errTooManyActiveUsers"; break;
        case JET_errInvalidCountry: errorString += "JET_errInvalidCountry"; break;
        case JET_errInvalidLanguageId: errorString += "JET_errInvalidLanguageId"; break;
        case JET_errInvalidCodePage: errorString += "JET_errInvalidCodePage"; break;
        case JET_errInvalidLCMapStringFlags: errorString += "JET_errInvalidLCMapStringFlags"; break;
        case JET_errVersionStoreEntryTooBig: errorString += "JET_errVersionStoreEntryTooBig"; break;
        case JET_errVersionStoreOutOfMemoryAndCleanupTimedOut: errorString += "JET_errVersionStoreOutOfMemoryAndCleanupTimedOut"; break;
        case JET_errVersionStoreOutOfMemory: errorString += "JET_errVersionStoreOutOfMemory"; break;
        case JET_errCannotIndex: errorString += "JET_errCannotIndex"; break;
        case JET_errRecordNotDeleted: errorString += "JET_errRecordNotDeleted"; break;
        case JET_errTooManyMempoolEntries: errorString += "JET_errTooManyMempoolEntries"; break;
        case JET_errOutOfObjectIDs: errorString += "JET_errOutOfObjectIDs"; break;
        case JET_errOutOfLongValueIDs: errorString += "JET_errOutOfLongValueIDs"; break;
        case JET_errOutOfAutoincrementValues: errorString += "JET_errOutOfAutoincrementValues"; break;
        case JET_errOutOfDbtimeValues: errorString += "JET_errOutOfDbtimeValues"; break;
        case JET_errOutOfSequentialIndexValues: errorString += "JET_errOutOfSequentialIndexValues"; break;
        case JET_errRunningInOneInstanceMode: errorString += "JET_errRunningInOneInstanceMode"; break;
        case JET_errRunningInMultiInstanceMode: errorString += "JET_errRunningInMultiInstanceMode"; break;
        case JET_errSystemParamsAlreadySet: errorString += "JET_errSystemParamsAlreadySet"; break;
        case JET_errSystemPathInUse: errorString += "JET_errSystemPathInUse"; break;
        case JET_errLogFilePathInUse: errorString += "JET_errLogFilePathInUse"; break;
        case JET_errTempPathInUse: errorString += "JET_errTempPathInUse"; break;
        case JET_errInstanceNameInUse: errorString += "JET_errInstanceNameInUse"; break;
        case JET_errInstanceUnavailable: errorString += "JET_errInstanceUnavailable"; break;
        case JET_errDatabaseUnavailable: errorString += "JET_errDatabaseUnavailable"; break;
        case JET_errInstanceUnavailableDueToFatalLogDiskFull: errorString += "JET_errInstanceUnavailableDueToFatalLogDiskFull"; break;
        case JET_errOutOfSessions: errorString += "JET_errOutOfSessions"; break;
        case JET_errWriteConflict: errorString += "JET_errWriteConflict"; break;
        case JET_errTransTooDeep: errorString += "JET_errTransTooDeep"; break;
        case JET_errInvalidSesid: errorString += "JET_errInvalidSesid"; break;
        case JET_errWriteConflictPrimaryIndex: errorString += "JET_errWriteConflictPrimaryIndex"; break;
        case JET_errInTransaction: errorString += "JET_errInTransaction"; break;
        case JET_errRollbackRequired: errorString += "JET_errRollbackRequired"; break;
        case JET_errTransReadOnly: errorString += "JET_errTransReadOnly"; break;
        case JET_errSessionWriteConflict: errorString += "JET_errSessionWriteConflict"; break;
        case JET_errRecordTooBigForBackwardCompatibility: errorString += "JET_errRecordTooBigForBackwardCompatibility"; break;
        case JET_errCannotMaterializeForwardOnlySort: errorString += "JET_errCannotMaterializeForwardOnlySort"; break;
        case JET_errSesidTableIdMismatch: errorString += "JET_errSesidTableIdMismatch"; break;
        case JET_errInvalidInstance: errorString += "JET_errInvalidInstance"; break;
        case JET_errDirtyShutdown: errorString += "JET_errDirtyShutdown"; break;
        // unused -1117
        case JET_errReadPgnoVerifyFailure: errorString += "JET_errReadPgnoVerifyFailure"; break;
        case JET_errReadLostFlushVerifyFailure: errorString += "JET_errReadLostFlushVerifyFailure"; break;
        case JET_errFileSystemCorruption: errorString += "JET_errFileSystemCorruption"; break;
        case JET_errRecoveryVerifyFailure: errorString += "JET_errRecoveryVerifyFailure"; break;
        case JET_errFilteredMoveNotSupported: errorString += "JET_errFilteredMoveNotSupported"; break;
        case JET_errDatabaseDuplicate: errorString += "JET_errDatabaseDuplicate"; break;
        case JET_errDatabaseInUse: errorString += "JET_errDatabaseInUse"; break;
        case JET_errDatabaseNotFound: errorString += "JET_errDatabaseNotFound"; break;
        case JET_errDatabaseInvalidName: errorString += "JET_errDatabaseInvalidName"; break;
        case JET_errDatabaseInvalidPages: errorString += "JET_errDatabaseInvalidPages"; break;
        case JET_errDatabaseCorrupted: errorString += "JET_errDatabaseCorrupted"; break;
        case JET_errDatabaseLocked: errorString += "JET_errDatabaseLocked"; break;
        case JET_errCannotDisableVersioning: errorString += "JET_errCannotDisableVersioning"; break;
        case JET_errInvalidDatabaseVersion: errorString += "JET_errInvalidDatabaseVersion"; break;
        // The following error code are for NT clients only. It will return wstring( such error during
        // JetInit if JET_paramCheckFormatWhenOpenFail is set.
        case JET_errDatabase200Format: errorString += "JET_errDatabase200Format"; break;
        case JET_errDatabase400Format: errorString += "JET_errDatabase400Format"; break;
        case JET_errDatabase500Format: errorString += "JET_errDatabase500Format"; break;
        case JET_errPageSizeMismatch: errorString += "JET_errPageSizeMismatch"; break;
        case JET_errTooManyInstances: errorString += "JET_errTooManyInstances"; break;
        case JET_errDatabaseSharingViolation: errorString += "JET_errDatabaseSharingViolation"; break;
        case JET_errAttachedDatabaseMismatch: errorString += "JET_errAttachedDatabaseMismatch"; break;
        case JET_errDatabaseInvalidPath: errorString += "JET_errDatabaseInvalidPath"; break;
        case JET_errDatabaseIdInUse: errorString += "JET_errDatabaseIdInUse"; break;
        case JET_errForceDetachNotAllowed: errorString += "JET_errForceDetachNotAllowed"; break;
        case JET_errCatalogCorrupted: errorString += "JET_errCatalogCorrupted"; break;
        case JET_errPartiallyAttachedDB: errorString += "JET_errPartiallyAttachedDB"; break;
        case JET_errDatabaseSignInUse: errorString += "JET_errDatabaseSignInUse"; break;
        case JET_errDatabaseCorruptedNoRepair: errorString += "JET_errDatabaseCorruptedNoRepair"; break;
        case JET_errInvalidCreateDbVersion: errorString += "JET_errInvalidCreateDbVersion"; break;
        case JET_errTableLocked: errorString += "JET_errTableLocked"; break;
        case JET_errTableDuplicate: errorString += "JET_errTableDuplicate"; break;
        case JET_errTableInUse: errorString += "JET_errTableInUse"; break;
        case JET_errObjectNotFound: errorString += "JET_errObjectNotFound"; break;
        case JET_errDensityInvalid: errorString += "JET_errDensityInvalid"; break;
        case JET_errTableNotEmpty: errorString += "JET_errTableNotEmpty"; break;
        case JET_errInvalidTableId: errorString += "JET_errInvalidTableId"; break;
        case JET_errTooManyOpenTables: errorString += "JET_errTooManyOpenTables"; break;
        case JET_errIllegalOperation: errorString += "JET_errIllegalOperation"; break;
        case JET_errTooManyOpenTablesAndCleanupTimedOut: errorString += "JET_errTooManyOpenTablesAndCleanupTimedOut"; break;
        case JET_errObjectDuplicate: errorString += "JET_errObjectDuplicate"; break;
        case JET_errInvalidObject: errorString += "JET_errInvalidObject"; break;
        case JET_errCannotDeleteTempTable: errorString += "JET_errCannotDeleteTempTable"; break;
        case JET_errCannotDeleteSystemTable: errorString += "JET_errCannotDeleteSystemTable"; break;
        case JET_errCannotDeleteTemplateTable: errorString += "JET_errCannotDeleteTemplateTable"; break;
        case JET_errExclusiveTableLockRequired: errorString += "JET_errExclusiveTableLockRequired"; break;
        case JET_errFixedDDL: errorString += "JET_errFixedDDL"; break;
        case JET_errFixedInheritedDDL: errorString += "JET_errFixedInheritedDDL"; break;
        case JET_errCannotNestDDL: errorString += "JET_errCannotNestDDL"; break;
        case JET_errDDLNotInheritable: errorString += "JET_errDDLNotInheritable"; break;
        case JET_errInvalidSettings: errorString += "JET_errInvalidSettings"; break;
        case JET_errClientRequestToStopJetService: errorString += "JET_errClientRequestToStopJetService"; break;
        case JET_errCannotAddFixedVarColumnToDerivedTable-1330: errorString += "JET_errCannotAddFixedVarColumnToDerivedTable-1330"; break;
        // DDL errors

        // Note: Some DDL errors have snuck into other categories.
        case JET_errIndexCantBuild: errorString += "JET_errIndexCantBuild"; break;
        case JET_errIndexHasPrimary: errorString += "JET_errIndexHasPrimary"; break;
        case JET_errIndexDuplicate: errorString += "JET_errIndexDuplicate"; break;
        case JET_errIndexNotFound: errorString += "JET_errIndexNotFound"; break;
        case JET_errIndexMustStay: errorString += "JET_errIndexMustStay"; break;
        case JET_errIndexInvalidDef: errorString += "JET_errIndexInvalidDef"; break;
        case JET_errInvalidCreateIndex: errorString += "JET_errInvalidCreateIndex"; break;
        case JET_errTooManyOpenIndexes: errorString += "JET_errTooManyOpenIndexes"; break;
        case JET_errMultiValuedIndexViolation: errorString += "JET_errMultiValuedIndexViolation"; break;
        case JET_errIndexBuildCorrupted: errorString += "JET_errIndexBuildCorrupted"; break;
        case JET_errPrimaryIndexCorrupted: errorString += "JET_errPrimaryIndexCorrupted"; break;
        case JET_errSecondaryIndexCorrupted: errorString += "JET_errSecondaryIndexCorrupted"; break;
        case JET_errInvalidIndexId: errorString += "JET_errInvalidIndexId"; break;
        case JET_errIndexTuplesSecondaryIndexOnly: errorString += "JET_errIndexTuplesSecondaryIndexOnly"; break;
        case JET_errIndexTuplesTooManyColumns: 
                errorString += "JET_errIndexTuplesTooManyColumns or JET_errIndexTuplesOneColumnOnly\n";
                break;
        case JET_errIndexTuplesNonUniqueOnly: errorString += "JET_errIndexTuplesNonUniqueOnly"; break;
        case JET_errIndexTuplesTextBinaryColumnsOnly: 
                errorString += "JET_errIndexTuplesTextBinaryColumnsOnly or JET_errIndexTuplesTextColumnsOnly\n";
                break;
        case JET_errIndexTuplesVarSegMacNotAllowed: errorString += "JET_errIndexTuplesVarSegMacNotAllowed"; break;
        case JET_errIndexTuplesInvalidLimits: errorString += "JET_errIndexTuplesInvalidLimits"; break;
        case JET_errIndexTuplesCannotRetrieveFromIndex: errorString += "JET_errIndexTuplesCannotRetrieveFromIndex"; break;
        case JET_errIndexTuplesKeyTooSmall: errorString += "JET_errIndexTuplesKeyTooSmall"; break;
        // DML errors

        // Note: Some DML errors have snuck into other categories.
        // Note: Some DDL errors have inappropriately snuck in here.
        case JET_errColumnLong: errorString += "JET_errColumnLong"; break;
        case JET_errColumnNoChunk: errorString += "JET_errColumnNoChunk"; break;
        case JET_errColumnDoesNotFit: errorString += "JET_errColumnDoesNotFit"; break;
        case JET_errNullInvalid:  // JET_errColumnIllegalNull
            errorString += "JET_errNullInvalid OR JET_errColumnIllegalNull\n"; 
            break;
        case JET_errColumnIndexed: errorString += "JET_errColumnIndexed"; break;
        case JET_errColumnTooBig: errorString += "JET_errColumnTooBig"; break;
        case JET_errColumnNotFound: errorString += "JET_errColumnNotFound"; break;
        case JET_errColumnDuplicate: errorString += "JET_errColumnDuplicate"; break;
        case JET_errMultiValuedColumnMustBeTagged: errorString += "JET_errMultiValuedColumnMustBeTagged"; break;
        case JET_errColumnRedundant: errorString += "JET_errColumnRedundant"; break;
        case JET_errInvalidColumnType: errorString += "JET_errInvalidColumnType"; break;
        case JET_errTaggedNotNULL: errorString += "JET_errTaggedNotNULL"; break;
        case JET_errNoCurrentIndex: errorString += "JET_errNoCurrentIndex"; break;
        case JET_errKeyIsMade: errorString += "JET_errKeyIsMade"; break;
        case JET_errBadColumnId: errorString += "JET_errBadColumnId"; break;
        case JET_errBadItagSequence: errorString += "JET_errBadItagSequence"; break;
        case JET_errColumnInRelationship: errorString += "JET_errColumnInRelationship"; break;
        case JET_errCannotBeTagged: errorString += "JET_errCannotBeTagged"; break;
        case JET_errDefaultValueTooBig: errorString += "JET_errDefaultValueTooBig"; break;
        case JET_errMultiValuedDuplicate: errorString += "JET_errMultiValuedDuplicate"; break;
        case JET_errLVCorrupted: errorString += "JET_errLVCorrupted"; break;
        case JET_errMultiValuedDuplicateAfterTruncation: errorString += "JET_errMultiValuedDuplicateAfterTruncation"; break;
        case JET_errDerivedColumnCorruption: errorString += "JET_errDerivedColumnCorruption"; break;
        case JET_errInvalidPlaceholderColumn: errorString += "JET_errInvalidPlaceholderColumn"; break;
        case JET_errColumnCannotBeCompressed: errorString += "JET_errColumnCannotBeCompressed"; break;
        case JET_errRecordNotFound: errorString += "JET_errRecordNotFound"; break;
        case JET_errRecordNoCopy: errorString += "JET_errRecordNoCopy"; break;
        case JET_errNoCurrentRecord: errorString += "JET_errNoCurrentRecord"; break;
        case JET_errRecordPrimaryChanged: errorString += "JET_errRecordPrimaryChanged"; break;
        case JET_errKeyDuplicate: errorString += "JET_errKeyDuplicate"; break;
        case JET_errAlreadyPrepared: errorString += "JET_errAlreadyPrepared"; break;
        case JET_errKeyNotMade: errorString += "JET_errKeyNotMade"; break;
        case JET_errUpdateNotPrepared: errorString += "JET_errUpdateNotPrepared"; break;
        case JET_errDataHasChanged: errorString += "JET_errDataHasChanged"; break;
        case JET_errLanguageNotSupported: errorString += "JET_errLanguageNotSupported"; break;
        case JET_errDecompressionFailed: errorString += "JET_errDecompressionFailed"; break;
        case JET_errUpdateMustVersion: errorString += "JET_errUpdateMustVersion"; break;
        // Sort Table errors

        case JET_errTooManySorts: errorString += "JET_errTooManySorts"; break;
        case JET_errInvalidOnSort: errorString += "JET_errInvalidOnSort"; break;
        // Other errors

        case JET_errTempFileOpenError: errorString += "JET_errTempFileOpenError"; break;
        case JET_errTooManyAttachedDatabases: errorString += "JET_errTooManyAttachedDatabases"; break;
        case JET_errDiskFull: errorString += "JET_errDiskFull"; break;
        case JET_errPermissionDenied: errorString += "JET_errPermissionDenied"; break;
        case JET_errFileNotFound: errorString += "JET_errFileNotFound"; break;
        case JET_errFileInvalidType: errorString += "JET_errFileInvalidType"; break;
        case JET_errAfterInitialization: errorString += "JET_errAfterInitialization"; break;
        case JET_errLogCorrupted: errorString += "JET_errLogCorrupted"; break;
        case JET_errInvalidOperation: errorString += "JET_errInvalidOperation"; break;
        case JET_errAccessDenied: errorString += "JET_errAccessDenied"; break;
        case JET_errTooManySplits: errorString += "JET_errTooManySplits"; break;
        case JET_errSessionSharingViolation: errorString += "JET_errSessionSharingViolation"; break;
        case JET_errEntryPointNotFound: errorString += "JET_errEntryPointNotFound"; break;
        case JET_errSessionContextAlreadySet: errorString += "JET_errSessionContextAlreadySet"; break;
        case JET_errSessionContextNotSetByThisThread: errorString += "JET_errSessionContextNotSetByThisThread"; break;
        case JET_errSessionInUse: errorString += "JET_errSessionInUse"; break;
        case JET_errRecordFormatConversionFailed: errorString += "JET_errRecordFormatConversionFailed"; break;
        case JET_errOneDatabasePerSession: errorString += "JET_errOneDatabasePerSession"; break;
        case JET_errRollbackError: errorString += "JET_errRollbackError"; break;
        case JET_errDatabaseAlreadyRunningMaintenance: errorString += "JET_errDatabaseAlreadyRunningMaintenance"; break;
        case JET_errCallbackFailed: errorString += "JET_errCallbackFailed"; break;
        case JET_errCallbackNotResolved: errorString += "JET_errCallbackNotResolved"; break;
        case JET_errSpaceHintsInvalid: errorString += "JET_errSpaceHintsInvalid"; break;
        case JET_errOSSnapshotInvalidSequence: errorString += "JET_errOSSnapshotInvalidSequence"; break;
        case JET_errOSSnapshotTimeOut: errorString += "JET_errOSSnapshotTimeOut"; break;
        case JET_errOSSnapshotNotAllowed: errorString += "JET_errOSSnapshotNotAllowed"; break;
        case JET_errOSSnapshotInvalidSnapId: errorString += "JET_errOSSnapshotInvalidSnapId"; break;
        case JET_errLSCallbackNotSpecified: errorString += "JET_errLSCallbackNotSpecified"; break;
        case JET_errLSAlreadySet: errorString += "JET_errLSAlreadySet"; break;
        case JET_errLSNotSet: errorString += "JET_errLSNotSet"; break;
        // FILE and DISK ERRORS
        //JET_errFileAccessDenied-1032
        //JET_errFileNotFound-1811
        //JET_errInvalidFilename-1044
        case JET_errFileIOSparse: errorString += "JET_errFileIOSparse"; break;
        case JET_errFileIOBeyondEOF: errorString += "JET_errFileIOBeyondEOF"; break;
        case JET_errFileIOAbort: errorString += "JET_errFileIOAbort"; break;
        case JET_errFileIORetry: errorString += "JET_errFileIORetry"; break;
        case JET_errFileIOFail: errorString += "JET_errFileIOFail"; break;
        case JET_errFileCompressed: errorString += "JET_errFileCompressed"; break;
        default:
            errorString += "JET Unknown error!";
    }
    errorString += "\n";

    return errorString;
}

jet_exception::jet_exception(std::string errorText, long errorCode)
    : db_exception(errorText, errorCode)
{
	BAJA_TRACE(GetJETErrorString(errorCode, errorText).c_str());
}
